using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;
using octopus_project.input;
using Nuclex.Input;
using octopus_project.scene;

namespace octopus_project.input {
    class InputHandler {

        protected KeyboardState CurrentKeyboardState;
        protected GamePadState CurrentGamePadState;
        protected MouseState CurrentMouseState;

        protected KeyboardState LastKeyboardState;
        protected GamePadState LastGamePadState;
        protected MouseState LastMouseState;

        protected InputManager input; // Class needed to get the Gamepad to work.
        
        //private Point _lastMouseLocation;
        //private Vector2 _mouseMoved;
        //public Vector2 MouseMoved {

        /// <summary>
        /// Description.
        /// </summary>
        public InputHandler () {
            input = new InputManager();
        }

        public void Update () {
            LastKeyboardState = CurrentKeyboardState;
            LastGamePadState = CurrentGamePadState;
            LastMouseState = CurrentMouseState;

            CurrentKeyboardState = Keyboard.GetState();
            input.Update();
            CurrentGamePadState = input.GetGamePad(PlayerIndex.One + 4).GetState();
            CurrentMouseState = Mouse.GetState();        
        }


        public bool IsButtonDown (Buttons button) {
            return CurrentGamePadState.IsButtonDown(button);
        }


        public bool IsKeyDown (Keys key) {
            return CurrentKeyboardState.IsKeyDown(key);
        }

        public bool IsKeyUp (Keys key) {
            return CurrentKeyboardState.IsKeyUp(key);
        }

        /// <summary>
        /// Helper for checking if a key was newly pressed during this update.
        /// </summary>
        public bool IsNewKeyPress (Keys key) {
            return (CurrentKeyboardState.IsKeyDown(key) &&
                    LastKeyboardState.IsKeyUp(key));
        }

        /// <summary>
        /// Helper for checking if a key was newly pressed during this update.
        /// </summary>
        public bool IsNewKeyRelease (Keys key) {
            return (LastKeyboardState.IsKeyDown(key) &&
                    CurrentKeyboardState.IsKeyUp(key));
        }

        /// <summary>
        /// Description.
        /// </summary>
        public bool IsNewButtonPress (Buttons button) {
            return (CurrentGamePadState.IsButtonDown(button) &&
                    LastGamePadState.IsButtonUp(button));
        }

    }
}